MkContainer
A node containing other MkNodes.
Note
Description
This is the concrete implementation with list-based storage. Can be used directly or as a base class. Nodes added to a container are automatically re-parented.
Examples
Example: Regular
Note
Jinja
{{ ["a = 1 + 2" | MkCode, "abc" | MkText] | MkContainer }}
Note
Python
MkContainer()
Rendered
a = 1 + 2
abc
a = 1 + 2
abc
Markdown
````python
a = 1 + 2
````
abc
````python
a = 1 + 2
````
abc
Html
<pre><code class="language-python">a = 1 + 2
</code></pre>
<p>abc</p>
<pre><code class="language-python">a = 1 + 2
</code></pre>
<p>abc</p>
Repr tree
MkContainer
├── MkCode(None)
│ ╰── MkText('a = 1 + 2')
├── MkText('abc')
╰── MkContainer()
├── MkCode(None)
│ ╰── MkText('a = 1 + 2')
├── MkText('abc')
Sub classes
| Name | Children | Inherits |
|---|---|---|
| MkBlock mknodes.basenodes.mkblock PyMdown-based block. | ||
| MkAdmonition mknodes.basenodes.mkadmonition Admonition info box. |
| |
| MkBlockQuote mknodes.basenodes.mkblockquote BlockQuote node. |
| |
| MkCode mknodes.basenodes.mkcode Class representing a Code block. | ||
| MkTemplate mknodes.templatenodes.mktemplate Node representing a jinja template. | ||
| MkList mknodes.basenodes.mklist Node for showing a formatted list. |
| |
| MkBaseTable mknodes.basenodes.mkbasetable Base Class for MkTables. Only deals with managing the data. | ||
| MkTab mknodes.basenodes.mktabs Node representing a single tab. |
| |
| MkTabContainer mknodes.basenodes.mktabcontainer Base class for nodes containing tabs. | ||
| MkCritic mknodes.basenodes.mkcritic MkCritic block. |
| |
| MkAnnotation mknodes.basenodes.mkannotations Represents a single annotation. It gets managed by an MkAnnotations node. |
| |
| MkAnnotations mknodes.basenodes.mkannotations Node containing a list of MkAnnotations. |
| |
| MkFootNote mknodes.basenodes.mkfootnotes Represents a single footnote. It gets managed by an MkFootNotes node. |
| |
| MkFootNotes mknodes.basenodes.mkfootnotes Node containing a list of MkFootNotes. |
| |
| MkDefinition mknodes.basenodes.mkdefinitionlist Node for a single definition. |
| |
| MkDefinitionList mknodes.basenodes.mkdefinitionlist Node for definition lists. |
| |
| MkPage mknodes.pages.mkpage A node container representing a Markdown page. | ||
| MkShowcase mknodes.basenodes.mkshowcase Node for showing a html-based image grid. |
| |
| MkSpeechBubble mknodes.basenodes.mkspeechbubble Node for showing a css-based speech bubble. |
| |
| MkTask mknodes.basenodes.mktasklist Node for a single task listitem. |
| |
| MkTaskList mknodes.basenodes.mktasklist Node for task lists. |
| |
| MkTimeline mknodes.basenodes.mktimeline Node to show a JavaScript-supported Timeline. |
| |
| MkShields mknodes.templatenodes.mkshields Container for Shields.io / GitHub badges. |
| |
| MkMetadataBadges mknodes.templatenodes.mkmetadatabadges Container node for a list of metadata badges. |
|
Base classes
| Name | Children | Inherits |
|---|---|---|
| MkContainerBase mknodes.basenodes.mkcontainer Abstract base class for nodes containing other MkNodes. |
⋔ Inheritance diagram
graph TD
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
NodeFile
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkcontainer/metadata.toml
[metadata]
icon = "mdi:database"
name = "MkContainer"
[examples.regular]
title = "Regular"
jinja = """
{{ ["a = 1 + 2" | MkCode, "abc" | MkText] | MkContainer }}
"""
Code
mknodes.basenodes.mkcontainer.MkContainer
class MkContainer(MkContainerBase):
"""A node containing other MkNodes.
This is the concrete implementation with list-based storage.
Can be used directly or as a base class.
Nodes added to a container are automatically re-parented.
"""
def __init__(
self,
content: list[Any] | str | mknode.MkNode | None = None,
*,
block_separator: str = "\n\n",
**kwargs: Any,
) -> None:
"""Constructor.
Args:
content: Child Nodes of this container
block_separator: Separator to put between blocks. Defaults to 2 linebreaks
kwargs: Keyword arguments passed to parent
"""
super().__init__(block_separator=block_separator, **kwargs)
match content:
case None:
self._items: list[mknode.MkNode] = []
case str():
self._items = [self.to_child_node(content)] if content else []
case mknode.MkNode():
self._items = [self.to_child_node(content)]
case list():
self._items = [self.to_child_node(i) for i in content]
case _:
raise TypeError(content)
def get_items(self) -> list[mknode.MkNode]:
"""Return the list of contained items."""
return self._items
def set_items(self, items: list[mknode.MkNode]) -> None:
"""Set the list of contained items."""
self._items = items
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
def create_section_for_nodes(
nav: mk.MkNav,
klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
for kls in klasses:
tpl = "classpage_custom.jinja"
page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
nav += page
if kls.STATUS:
page.metadata.status = kls.STATUS
elif kls.JS_FILES:
page.metadata.status = "js"
elif kls.CSS:
page.metadata.status = "css"
page.created_by = create_section_for_nodes
link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
table.add_row((link, kls.__doc__, extensions))
return table
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7d707a397060>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: create_section_for_nodes
source_line_no: 93
hide:
- toc
icon: material/database
title: MkContainer